package com.situ.water_system.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.situ.water_system.pojo.SyArea;
import com.situ.water_system.mapper.SyAreaMapper;
import com.situ.water_system.service.SyAreaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.situ.water_system.util.Mingli;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@Mingli
public class SyAreaServiceImpl extends ServiceImpl<SyAreaMapper, SyArea> implements SyAreaService {
       @Autowired
      private SyAreaMapper dao;
      public List<SyArea> selectList(){
        return  dao.selectList(null);
      }
      @Transactional
      public int del(Serializable id){
          return dao.deleteById(id);
      }
    @Transactional
      public int add(SyArea syArea){
          return dao.insert(syArea);
      }
    @Transactional
      public int update(SyArea syArea){
          return dao.updateById(syArea);
      }
      public SyArea selectByid(Serializable id){
       return  dao.selectById(id);
      }
      public XSSFWorkbook select_excel(){
          List<SyArea> list = dao.selectList(null);//查出数据库数据
          XSSFWorkbook wb = new XSSFWorkbook();
          Sheet sheet = wb.createSheet("Goods");//创建一张表
          Row titleRow = sheet.createRow(0);//创建第一行，起始为0
          titleRow.createCell(0).setCellValue("序号");//第一列
          titleRow.createCell(1).setCellValue("名称");
          titleRow.createCell(2).setCellValue("备注");
          int cell = 1;
          for (SyArea goods : list) {
              Row row = sheet.createRow(cell);//从第二行开始保存数据
              row.createCell(0).setCellValue(cell);
              row.createCell(1).setCellValue(goods.getId());//将数据库的数据遍历出来
              row.createCell(2).setCellValue(goods.getAreaName());
              row.createCell(3).setCellValue(goods.getRemark());
              cell++;
          }
          return wb;

      }
}

